package cn.cs.yangtai.service.impl;

import cn.cs.yangtai.entity.Classification;
import cn.cs.yangtai.entity.Comminicate;
import cn.cs.yangtai.entity.vo.PageResult;
import cn.cs.yangtai.mapper.ComminicateMapper;
import cn.cs.yangtai.service.ComminicateService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;

/**
 * (Comminicate)表服务实现类
 *
 * @author makejava
 * @since 2024-12-12 09:22:52
 */
@Service("comminicateService")
public class ComminicateServiceImpl implements ComminicateService {
    @Resource
    private ComminicateMapper comminicateMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param iId 主键
     * @return 实例对象
     */
    @Override
    public Comminicate queryById(Integer iId) {
        return this.comminicateMapper.queryById(iId);
    }

    /**
     * 分页查询
     *
     * @param cuttentPage 本页
     * @param pageSize    分页大小
     * @return 查询结果
     */
    @Override
    public PageResult<Comminicate> queryByPage(Integer cuttentPage, Integer pageSize) {
        PageHelper.startPage(cuttentPage,pageSize);
        Page<Comminicate> comminicates =comminicateMapper.queryAllByLimit(new Page<>());
        return PageResult.restPage(comminicates);
    }

    /**
     * 新增数据
     *
     * @param comminicate 实例对象
     * @return 实例对象
     */
    @Override
    public Comminicate insert(Comminicate comminicate) {
        this.comminicateMapper.insert(comminicate);
        return comminicate;
    }

    /**
     * 修改数据
     *
     * @param comminicate 实例对象
     * @return 实例对象
     */
    @Override
    public Comminicate update(Comminicate comminicate) {
        this.comminicateMapper.update(comminicate);
        return this.queryById(comminicate.getIId());
    }

    /**
     * 通过主键删除数据
     *
     * @param iId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer iId) {
        return this.comminicateMapper.deleteById(iId) > 0;
    }
}
